/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-08-17 17:43:20
 * @LastEditTime: 2022-08-18 11:22:24
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import {
  SET_SELECT_AT,
  SET_SELECT_AT_ID,
  SET_SELECT_FOND_ID,
  SET_SELECTED_ITEM
} from '../constants';
import { OfflineBackupReducer } from '../reducers/OfflineBackupReducer';
const initialState = { delId: [] };
const OfflineBackupContext = createContext();
const OfflineBackupContextProvider = (props) => {
  const [state, dispatch] = useReducer(OfflineBackupReducer, initialState);
  const actions = {
    /**
     * @description: 设置选中的档案类型
     */
    setSelectAT(data) {
      dispatch({ type: SET_SELECT_AT, data });
    },

    /**
     * @description: 设置选中的全宗
     */
    setSelectFondId(id) {
      dispatch({ type: SET_SELECT_FOND_ID, id });
    },

    /**
     * @description: 设置选中的档案类型ID
     */
    setSelectATId(id) {
      dispatch({ type: SET_SELECT_AT_ID, id });
    },
    /**
     * @description: 设置表格中选中条目的key
     * @param {*} selectArr
     * @return {*}
     */
    setSelectKey(selectArr) {
      console.log(selectArr);
      dispatch({ type: SET_SELECTED_ITEM, data: selectArr });
    }
  };
  useEffect(() => {}, []);
  return (
    <OfflineBackupContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </OfflineBackupContext.Provider>
  );
};
export const useOfflineBackupContext = () => {
  return useContext(OfflineBackupContext);
};
export { OfflineBackupContext, OfflineBackupContextProvider };
